package com.netflix.appinfo;

import javax.inject.Provider;

import com.google.inject.Inject;

public class CloudInstanceConfigProvider implements Provider<CloudInstanceConfig> {

    @Inject(optional = true)
    @EurekaNamespace
    private String namespace;

    private CloudInstanceConfig config;

    @Override
    public synchronized CloudInstanceConfig get() {
        if (config == null) {
            if (namespace == null) {
                config = new CloudInstanceConfig();
            } else {
                config = new CloudInstanceConfig(namespace);
            }
            // TODO: Remove this when DiscoveryManager is finally no longer used
            DiscoveryManager.getInstance().setEurekaInstanceConfig(config);
        }
        return config;
    }
}

